<template>
  <header>
    <HeaderNav />
  </header>
  <div class="vr-content">
    <main class="a">
      <div class="vrsub" v-for="item in sublib" :key="item.SublibNo" @click="vrBtn">
        <el-button>{{ item.Sublib }}</el-button>
      </div>
    </main>
    <footer></footer>
  </div>
</template>
<script setup lang="ts">
import { getUrlParam } from '@/utils/arge-plug-in';
import { encode } from '@/utils/arge-plug-in';
import { useVrlibStore } from '@/stores/modules/vrlibStore';
import { libfloor } from '@/api/products';
interface sublib {
  SublibNo: string;
  Sublib: string;
}
const sublib = ref<sublib[]>();
const router = useRouter();
const mlib = getUrlParam('a');
const useStore = useVrlibStore();

if (mlib) {
  useStore.mlib = mlib;
} else {
  ElMessage.error('a参数mlib为空未选取学校');
}

const vrlib = (mlib: string): void => {
  const prdata = {
    a: `[Lib={{${mlib}}}]`,
  };
  libfloor(prdata)
    .then((res) => {
      const list1 = res.vr_ifa_Lib_GetFloor_list1;
      const list2 = res.vr_ifa_Lib_GetFloor_list2;
      useStore.floor = encode(list2[0].Floor).replace(/[\u4e00-\u9fa5]/g, 'F');
      useStore.floorNo = encode(list2[0].FloorNo);
      useStore.floorindex = 0;
      const sublibArray = [];
      for (let i in list1) {
        const sublibNo = encode(list1[i].SublibNo);
        const sublib = encode(list1[i].Sublib);
        const sublibobj = { SublibNo: sublibNo, Sublib: sublib };
        sublibArray.push(sublibobj);
      }
      sublib.value = sublibArray;
      console.log(sublibArray);
    })
    .catch((error) => {
      console.log(error);
    });
};
const vrBtn = () => {
  router.push({
    path: '/vrlib',
  });
};
onMounted(() => {
  vrlib(mlib!);
});
</script>
<style scoped lang="scss">
@media screen and (min-width: 1440px) {
  .vr-content {
    max-width: calc(var(--vp-screen-max-width));
  }
}
@media screen and (min-width: 1680px) {
  .vr-content {
    max-width: calc(var(--vp-screen-max-width));
  }
}
.vr-content {
  margin: 0 auto;
  position: relative;
  overflow: overlay;
  .a {
    padding-top: 80px;
    height: 2000px;
    overflow: overlay;
  }
}
</style>
